import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)


const store = new Vuex.Store({
  state: {
    count1: 0,
    count2: 0,
    count3: 0,
    count4: 0,
    buyCar1: [],
    buyCar2: [],
    buyCar3: [],
    buyCar4: [],
    loginStatus: false,
    loginName: '',
  },
  mutations: {
    editCount(state, val) {
      // console.log(val);
      state['count' + val[0]] = val[1]
    },
    getBuyCar(state, ary) {
      state['buyCar' + ary[0]] = ary[1]
    },
    loginSucess(state, loginInfo) {
      state.loginStatus = true
      state.loginName = loginInfo
    },
    loginout(state) {
      state.loginStatus = false
      state.loginName = ''
    }
  },
  getters: {
    doneCount: state => {
      return state.count1 + state.count2 + state.count3 + state.count4
    },
    doneBuyCar: state => {
      return state.buyCar1.concat(state.buyCar2, state.buyCar3, state.buyCar4)
    }
  }
})

export default store
